{template 'common/header-base'}
<div class="user-login system-forget">
	<div class="login-header">
		<div class="container">
			<h3>绑定已有用户</h3>
		</div>
	</div>
	<div class="login-content" id="js-users-console" ng-controller="UsersConsole" ng-cloak>
		<div class="alert we7-page-alert"><i class="wi wi-info"></i>您需要输入系统原用户名和密码，与控制台账号进行关联绑定，后期可直接登录控制台 <a href="https://c.w7.com" target="_blank" class="color-default">c.w7.com</a> 管理系统</div>
		<form action="javascript:;" class="form login-form">
			<div class="form-group">
				<label class="control-label col-sm-1">用户名:</label>
				<div class="col-sm-11">
					<div class="form-controls">
						<input type="username" class="form-control" placeholder="请输入系统原用户名" ng-model="username">
						<span class="text-error username"></span>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-1">密码:</label>
				<div class="col-sm-11">
					<div class="form-controls">
						<input type="password" class="form-control" placeholder="请输入系统密码" ng-model="password">
						<span class="text-error password"></span>
					</div>
				</div>
			</div>
			<div class="form-group" style="margin-top: -15px;">
				<div class="pull-right">
					<a href="{php echo url('user/find-password')}" class="color-default">忘记密码？</a>
				</div>
			</div>
			<div class="text-center">
				<input value="绑 定" class="btn btn-primary" style="width: 57%" ng-click="bindConsole()">
				<span class="text-error bind-console"></span>
			</div>
		</form>
	</div>
</div>
<div class="console-page hide">
	<div class="console-page__head">
		<a href="{$_W['siteroot']}">
			<img src="{if !empty($_W['setting']['copyright']['flogo'])}{php echo to_global_media($_W['setting']['copyright']['flogo'])}{else}./resource/images/logo/logo-219.png{/if}" class="logo" style="max-height: 40px;">
		</a>
		<div class="skin-2__header">
			<ul class="user-info">
				{template 'common/header-user'}
			</ul>
		</div>
	</div>
	<div class="console-page__body">
		<h1>选择身份登录</h1>
		<div class="alert alert-info">
			<i class="wi wi-info"></i> 管理员已将系统客户端移至控制台，请登录应用市场（s.w7.cc），点击顶部导航条中的控制台菜单进行操作。
		</div>
		<div class="console-type">
			{if !empty($_W['isadmin'])}
			<a href="{php echo url('user/third-bind/console_url', array('type' => 'we7'))}" class="console-item">
				<i class="wi wi-apply console-item__icon"></i>
				<div class="console-item__title">
					站点控制台
				</div>
				<div class="console-item__desc">站点控制台可以管理创始人账号下的所有微擎站点，拥有站点管理，应用管理，权限组及用户管理等管理功能</div>
				<button class="btn btn-default">创始人使用</button>
			</a>
			{/if}
			<a href="{php echo url('user/third-bind/console_url', array('type' => 'client'))}" class="console-item">
				<i class="wi wi-co-founder console-item__icon"></i>
				<div class="console-item__title">
					客户端控制台
				</div>
				<div class="console-item__desc">进入当前站点的用户操作后台，可创建公众号、小程序等平台类型以及操作账号权限内的相关功能</div>
				<button class="btn btn-default">用户使用</button>
			</a>
			{if !empty($_W['isadmin'])}
			<a href="{php echo url('user/third-bind/console_url', array('type' => 'system'))}" class="console-item">
				<i class="wi wi-co-founder console-item__icon"></i>
				<div class="console-item__title">
					返回旧版
				</div>
				<div class="console-item__desc">返回旧版代表关闭新版体验，如需重新开启，前往站点控制台->站点/菜单设置->站点设置->开启云端控制台模式</div>
				<button class="btn btn-default">返回旧版</button>
			</a>
			{/if}
		</div>
	</div>
</div>
<script type="text/javascript">
	angular.module('userManageApp').value('config', {
		'code' : "{php echo !empty($_GPC['code']) ? $_GPC['code'] : ''}",
		'openid' : "{php echo !empty($_GPC['openid']) ? $_GPC['openid'] : ''}",
		'links' : {
			'bind_console': "{php echo url('user/third-bind/bind_console', array('code' => $_GPC['code']))}",
		},
	});
	angular.module('userManageApp').controller('UsersConsole', ['$scope', '$http', 'config', function ($scope, $http, config) {
		$scope.links = config.links;
		$scope.username = '';
		$scope.password = '';

		$scope.bindConsole = function () {
			$('.username').html('');
			$('.password').html('');
			if ($scope.username == '') {
				$('.username').html('用户名不能为空');
				return false;
			}
			if ($scope.password == '') {
				$('.password').html('密码不能为空');
				return false;
			}
			//检验用户名密码并绑定
			$http.post($scope.links.bind_console, {
				code: config.code,
				openid: config.openid,
				username:$scope.username,
				password:$scope.password,
			}).success(function (data) {
				if (data.message.errno == 0) {
					util.message(data.message.message, data.redirect, 'success');
				} else {
					util.message(data.message.message);
				}
			});
		};
	}]);
	angular.bootstrap($('#js-users-console'), ['userManageApp']);
</script>
{template 'common/footer'}
